package com.atguigu.queue;

/**
 * 队列
 *
 * @author dataexa
 * @Date 2023/11/14
 */
public class ArrayQueueDemo {
    public static void main(String[] args) {
        ArrayQueue arrayQueue = new ArrayQueue(10);
    }
}

/**
 * 普通队列
 */
class ArrayQueue {
    private int maxSize;
    private int[] arr;
    int front;
    int real;

    public ArrayQueue(int maxSize) {
        arr = new int[maxSize];
        this.maxSize = maxSize;
        front = -1;
        real = -1;
    }

    public boolean isEmpty() {
        return this.front == this.real;
    }

    public boolean isFull() {
        return this.real == this.maxSize - 1;
    }

    public void addQueue(int n) {
        if (isFull()) {
            return;
        }
        this.real++;
        this.arr[this.real] = n;
    }

    public int removeQueue() {
        if (isEmpty()) {
            return -1;
        }
        this.front++;
        return this.arr[this.front];
    }
}

/**
 * 循环队列
 */
class CircleArray {
    private int maxSize;
    private int front = 0;
    private int real = 0;
    private int[] arr;

    public CircleArray(int maxSize) {
        this.maxSize = maxSize;
        this.arr = new int[maxSize];
    }

    public boolean isEmpty() {
        return this.front == this.real;
    }

    public boolean isFull() {
        return (this.real + 1) % this.maxSize == this.front;
    }

    public void addQueue(int n) {
        this.arr[this.real] = n;
        this.real = (this.real + 1) % this.maxSize;
    }

    public int removeQueue() {
        int value = this.arr[this.front];
        this.front = (this.real + 1) % this.maxSize;
        return value;
    }

}